package com.itheima;


import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;

/**
 * @auther Macrydy
 * @date 2020/7/10 18:31
 */
public class UdpClient {
    public static void main(String[] args) throws Exception {
        //创建通道
        DatagramSocket ds = new DatagramSocket();
        Scanner scanner = new Scanner(System.in);

        while (true) {
            //构建数据
            String s = scanner.nextLine();
            byte[] bytes = s.getBytes();
            //创建数据包
            DatagramPacket dp = new DatagramPacket(
                    bytes,
                    bytes.length,
                    InetAddress.getByName("127.0.0.1"),
                    10101);
            //发送
            ds.send(dp);
        }
//        ds.close();
    }
}
